package com.wn.network.interceptor

import com.blankj.utilcode.util.AppUtils
import com.blankj.utilcode.util.DeviceUtils
import okhttp3.Interceptor
import okhttp3.Response
import java.net.URLEncoder
import javax.inject.Inject
import javax.inject.Singleton

/**
 * @Author: wn
 * @Date: 2024/8/1 16:41
 * @Description: 公共参数拦截器 , 设备信息
 */
@Singleton
class PublicParameterInterceptor @Inject constructor() : Interceptor {
  override fun intercept(chain: Interceptor.Chain): Response {
    val request = chain.request()
    val newBuilder = request.newBuilder().apply {
      addHeader("device-type", "android")
      // 获取 App 版本号
      addHeader("app-version", AppUtils.getAppVersionName())
      // 获取设备 AndroidID
      addHeader("device-id", DeviceUtils.getAndroidID())
      // 获取设备系统版本号
      addHeader("device-os-version", DeviceUtils.getSDKVersionName())
      // 获取设备厂商(品牌) _ 获取设备型号
      val deviceNameStr = DeviceUtils.getManufacturer().plus("_")
        .plus(DeviceUtils.getModel())
      addHeader("device-name", URLEncoder.encode(deviceNameStr, "UTF-8"))
    }

    return chain.proceed(newBuilder.build())
  }
}